package actions;

import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
import jason.asSyntax.Term;

import java.util.Random;

@SuppressWarnings("serial")
public class random_direction extends DefaultInternalAction{

	@Override
	public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
		
		Term direction = args[0];
		
		Random r = new Random();
		int nextInt = r.nextInt(8);
		
		Direction direc = null;
		
		switch(nextInt) {
			case 0:
				direc = Direction.NORTH;
				break;
			case 1:
				direc = Direction.SOUTH;
				break;
			case 2:
				direc = Direction.WEST;
				break;
			case 3:
				direc = Direction.EAST;
				break;
			case 4:
				direc = Direction.NORTHEAST;
				break;
			case 5:
				direc = Direction.NORTHWEST;
				break;
			case 6:
				direc = Direction.SOUTHEAST;
				break;
			case 7:
				direc = Direction.SOUTHWEST;
				break;
			default:
				direc = Direction.NORTH;
		}

		Thread.sleep(500);
		un.unifies(direction, new Atom(direc.getValue()));
		
		// everything ok, so returns true
		return true;
	}
}